package com.acoffee.maven.controller;

import com.acoffee.maven.bean.UserVo;
import com.acoffee.maven.pojo.User;
import com.acoffee.maven.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author acoffee
 * @create 2021-05-14 15:38
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 控制器中的处理方法的返回值为跳转路径
     * 此功能讲解从前台传递对象到控制器
     * 如果使用的是对象的传值，那些只要前台的表单的name的值和对象中的属性名的值相同就可以接受到数据
     */
    @RequestMapping(value="/list")
    public String list(UserVo userVo, HttpServletRequest request){
        List<User> userList = userService.findUserByPage(userVo);
        request.setAttribute("userlist",userList);//转发设置到requset域中
        request.setAttribute("uv",userVo);
        return "/user/list.jsp";
    }
}
